package feizhou.untils.tools;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.Logger;


/***
 * 音频转换辅助类
 *
 * @author ryan
 *
 */
public class AudioConverterUtil {

    private static Logger log = Logger.getLogger(String.valueOf(AudioConverterUtil.class));

    //	static String ffmpegApp="D:/back02017805/firefox-down/ffmpeg-20170221-a5c1c7a-win64-static/bin/ffmpeg.exe";
    static String ffmpegApp = "/usr/local/bin/ffmpeg";

    public static void compressVideo(String src, String des) {
        ProcessBuilder processBuilder = new ProcessBuilder(ffmpegApp, "-i", src, "-b:v", "1600k", "-vcodec", "h264", des);
        BufferedReader br = null;
        InputStreamReader isr = null;
        InputStream stderr = null;
        try {
            Process process = processBuilder.start();

            stderr = process.getErrorStream();
            isr = new InputStreamReader(stderr);
            br = new BufferedReader(isr);
            String line;
            // 打印 sb，获取更多信息。 如 bitrate、width、heigt
            StringBuffer sb = new StringBuffer();
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }

            process.waitFor();

        } catch (Exception e) {
            log.info("getInfo error" + e);
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
                if (isr != null) {
                    isr.close();
                }
                if (stderr != null) {
                    stderr.close();
                }
            } catch (Exception e2) {
            }
        }
    }

}
